import { mapGetters } from "vuex";

export default {
	computed: {
		...mapGetters('cart', ['goodsInfo'])
	},

	data () {
		return {
			length: 0
		};
	},

	onShow () {
		if (this.goodsInfo.length) {
			this.length = this.goodsInfo.length
		} else {
			return
		}
		this.setBadge()
	},

	watch: {
		length () {
			this.setBadge()
		}
	},

	methods: {
		setBadge () {
			if (this.length) {
				uni.setTabBarBadge({
					index: 2,
					text: `${this.length}`
				})
			} else {
				uni.removeTabBarBadge({ index: 2 })
			}
		}
	}
}